package controllers;

import java.io.IOException;

import ccrm.ClientMain;
import entitys.Area;
import entitys.Category;
import entitys.Request;
import entitys.Session;
import enums.Command;
import boundarys.MaintainingResidentialAreaGUI;

public class MaintainingResidentialAreaController {

	MaintainingResidentialAreaGUI mra;

	public MaintainingResidentialAreaController(MaintainingResidentialAreaGUI mra)
	{
		this.mra=mra;
	}
	
	/**
	 * sends request to server to get areas list
	 */
	public static void getAreas() {
		// TODO Auto-generated method stub
		Request r =new Request(Command.GET_AREAS,Session.getEmployee().getUserId());
		
		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * sends request to server to get areas list that contains the string area)
	 * @param area
	 */
	public static void getAreas(String area) {
		// TODO Auto-generated method stub
		Request r =new Request(Command.GET_AREAS_WITH_PREFIX,Session.getEmployee().getUserId(), new Area(area));
		
		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	/**
	 * sends request to server to delete the area
	 * @param area
	 * @param aid
	 */
	public static void deleteArea(String area, int aid) {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
		Request r =new Request(Command.DELETE_AREA,Session.getEmployee().getUserId(), new Area(area, aid));
		
		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * sends request to server to add new area to the database
	 * @param area
	 * @param itemCount
	 */
	public static void addArea(String area, int itemCount) {
		// TODO Auto-generated method stub
		Request r =new Request(Command.ADD_AREA,Session.getEmployee().getUserId(), new Area(area, itemCount+1));
		
		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
